from __future__ import annotations

from sqlalchemy import ForeignKey, JSON, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column

from app.db.base_class import BaseEntity


class MemoryEdge(BaseEntity):
  __tablename__ = "memory_edges"
  __table_args__ = (
    UniqueConstraint("user_id", "relationship_id", "type", "src_id", "dst_id", name="uq_memory_edges_scope"),
  )

  user_id: Mapped[int] = mapped_column(index=True)
  relationship_id: Mapped[int | None] = mapped_column(ForeignKey("relationships.id"), index=True)
  src_id: Mapped[int] = mapped_column(ForeignKey("memory_nodes.id", ondelete="CASCADE"), index=True)
  dst_id: Mapped[int] = mapped_column(ForeignKey("memory_nodes.id", ondelete="CASCADE"), index=True)
  type: Mapped[str] = mapped_column(String(32), index=True)
  props_json: Mapped[dict] = mapped_column(JSON, default=dict)

